package fr.vincent.aquarium.ws;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import fr.vincent.aquarium.metier.article.Article;
import fr.vincent.aquarium.service.AquariumService;

@Controller
@RequestMapping("/article")
public class RestServlet {
	
	@Autowired
	private AquariumService service;
	
	@RequestMapping(value = "{idArticle}/info", method = RequestMethod.GET)
	public @ResponseBody Article getArticle(@PathVariable Long idArticle){
		return this.service.getArticle(idArticle);
	}
	
	@RequestMapping("/info")
	public @ResponseBody List<Article> getArticle(){
		RestTemplate rest = new RestTemplate();
		rest.delete("http://localhost:8080/st/article/1/delete");
		
		return this.service.getArticle();
	}
	
	@RequestMapping(value = "{idArticle}/delete", method = RequestMethod.DELETE)
	public @ResponseBody void delete(@PathVariable Long idArticle){

		this.service.supprimer(idArticle);
	}
}
 